﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Collections.Specialized;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Xml.Linq;
using System.Web.DynamicData;
using System.ComponentModel.DataAnnotations;

public partial class Decimal_PercentEditField : System.Web.DynamicData.FieldTemplateUserControl 
{
    
    protected void Page_Load(object sender, EventArgs e)
    {
        WebPercentEdit1.ToolTip = Column.Description;
        RangeAttribute attr = this.Column.Attributes[typeof(RangeAttribute)] as RangeAttribute;
        if (attr != null)
        {

            this.WebPercentEdit1.MinValue = System.Convert.ToDouble(attr.Minimum);
            this.WebPercentEdit1.MaxValue = System.Convert.ToDouble(attr.Maximum);
        }

    }
    protected override void OnDataBinding(EventArgs e)
    {
        base.OnDataBinding(e);

        if (Mode == DataBoundControlMode.Edit)
        {
            if (FieldValue != null)
            {
                decimal fieldvalue = System.Convert.ToDecimal(this.FieldValue);
                this.WebPercentEdit1.Value = fieldvalue * 100;
            }
        }
    }
    protected override void ExtractValues(IOrderedDictionary dictionary) 
    {
        dictionary[Column.Name] = ConvertEditedValue((WebPercentEdit1.ValueDecimal/100).ToString());
    }
}
